<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - sockets_extensions.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2006  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_SOCKETS_EXTENSIONs_
<font color='#0000FF'>#define</font> DLIB_SOCKETS_EXTENSIONs_

<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>string<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../sockets.h.html'>../sockets.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='sockets_extensions_abstract.h.html'>sockets_extensions_abstract.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../smart_pointers.h.html'>../smart_pointers.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>iosfwd<font color='#5555FF'>&gt;</font>

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='invalid_network_address'></a>invalid_network_address</b> : <font color='#0000FF'>public</font> dlib::error 
    <b>{</b> 
    <font color='#0000FF'>public</font>: 
        <b><a name='invalid_network_address'></a>invalid_network_address</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> msg<font face='Lucida Console'>)</font> : dlib::error<font face='Lucida Console'>(</font>msg<font face='Lucida Console'>)</font> <b>{</b><b>}</b>;
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>struct</font> <b><a name='network_address'></a>network_address</b>
    <b>{</b>
        <b><a name='network_address'></a>network_address</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> : port<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font><b>{</b><b>}</b>

        <b><a name='network_address'></a>network_address</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> full_address
        <font face='Lucida Console'>)</font>;

        <b><a name='network_address'></a>network_address</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> full_address
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#5555FF'>*</font><font color='#0000FF'>this</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>network_address</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>string</font><font face='Lucida Console'>(</font>full_address<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <b><a name='network_address'></a>network_address</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> host_address_,
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>short</u></font> port_
        <font face='Lucida Console'>)</font> : host_address<font face='Lucida Console'>(</font>host_address_<font face='Lucida Console'>)</font>, port<font face='Lucida Console'>(</font>port_<font face='Lucida Console'>)</font> <b>{</b><b>}</b>
            
        std::string host_address;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>short</u></font> port;
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b> <font color='#5555FF'>&lt;</font> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> network_address<font color='#5555FF'>&amp;</font> a,
        <font color='#0000FF'>const</font> network_address<font color='#5555FF'>&amp;</font> b
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>a.host_address <font color='#5555FF'>&lt;</font> b.host_address<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>a.host_address <font color='#5555FF'>&gt;</font> b.host_address<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>a.port <font color='#5555FF'>&lt;</font> b.port<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <font color='#0000FF'>else</font>
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
    <b>}</b>

    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> network_address<font color='#5555FF'>&amp;</font> a,
        <font color='#0000FF'>const</font> network_address<font color='#5555FF'>&amp;</font> b
    <font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> a.host_address <font color='#5555FF'>=</font><font color='#5555FF'>=</font> b.host_address <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> a.port <font color='#5555FF'>=</font><font color='#5555FF'>=</font> b.port; <b>}</b>

    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> network_address<font color='#5555FF'>&amp;</font> a,
        <font color='#0000FF'>const</font> network_address<font color='#5555FF'>&amp;</font> b
    <font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#5555FF'>!</font><font face='Lucida Console'>(</font>a <font color='#5555FF'>=</font><font color='#5555FF'>=</font> b<font face='Lucida Console'>)</font>; <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='serialize'></a>serialize</b><font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> network_address<font color='#5555FF'>&amp;</font> item,
        std::ostream<font color='#5555FF'>&amp;</font> out
    <font face='Lucida Console'>)</font>;

    <font color='#0000FF'><u>void</u></font> <b><a name='deserialize'></a>deserialize</b><font face='Lucida Console'>(</font>
        network_address<font color='#5555FF'>&amp;</font> item,
        std::istream<font color='#5555FF'>&amp;</font> in 
    <font face='Lucida Console'>)</font>;

    std::ostream<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font face='Lucida Console'>(</font>
        std::ostream<font color='#5555FF'>&amp;</font> out,
        <font color='#0000FF'>const</font> network_address<font color='#5555FF'>&amp;</font> item
    <font face='Lucida Console'>)</font>;

    std::istream<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> <font face='Lucida Console'>(</font>
        std::istream<font color='#5555FF'>&amp;</font> in,
        network_address<font color='#5555FF'>&amp;</font> item
    <font face='Lucida Console'>)</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    connection<font color='#5555FF'>*</font> <b><a name='connect'></a>connect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> host_or_ip,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>short</u></font> port
    <font face='Lucida Console'>)</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    connection<font color='#5555FF'>*</font> <b><a name='connect'></a>connect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> network_address<font color='#5555FF'>&amp;</font> addr
    <font face='Lucida Console'>)</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    connection<font color='#5555FF'>*</font> <b><a name='connect'></a>connect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> host_or_ip,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>short</u></font> port,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> timeout
    <font face='Lucida Console'>)</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> <b><a name='is_ip_address'></a>is_ip_address</b> <font face='Lucida Console'>(</font>
        std::string ip
    <font face='Lucida Console'>)</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='close_gracefully'></a>close_gracefully</b> <font face='Lucida Console'>(</font>
        connection<font color='#5555FF'>*</font> con,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> timeout <font color='#5555FF'>=</font> <font color='#979000'>500</font>
    <font face='Lucida Console'>)</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='close_gracefully'></a>close_gracefully</b> <font face='Lucida Console'>(</font>
        scoped_ptr<font color='#5555FF'>&lt;</font>connection<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> con,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> timeout <font color='#5555FF'>=</font> <font color='#979000'>500</font>
    <font face='Lucida Console'>)</font>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#ifdef</font> NO_MAKEFILE
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='sockets_extensions.cpp.html'>sockets_extensions.cpp</a>"
<font color='#0000FF'>#endif</font>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_SOCKETS_EXTENSIONs_
</font>

</pre></body></html>